package xujiwen.transport.servlet.listener;


import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import xujiwen.transport.util.StaticData;
import xujiwen.transport.util.xml.been.DatabaseXML;
import xujiwen.transport.util.xml.been.manager.DatabaseXMLManager;

public class MyListener implements HttpSessionListener,
		HttpSessionAttributeListener, ServletContextListener {

	public void sessionCreated(final HttpSessionEvent arg) {
		System.out.println("创建了一个session");

	}

	public void sessionDestroyed(final HttpSessionEvent arg0) {
		System.out.println("注销了一个session");
	}

	public void attributeAdded(final HttpSessionBindingEvent arg) {
		System.out.println("添加了一个session属性:" + arg.getName());

	}

	public void attributeRemoved(final HttpSessionBindingEvent arg) {
		System.out.println("删除了一个session属性:" + arg.getName());

	}

	public void attributeReplaced(final HttpSessionBindingEvent arg0) {
		System.out.println("重设了一个session属性");

	}

	public void contextDestroyed(final ServletContextEvent arg) {
		System.out.println("注销了一个application");
		StaticData.application = null;
	}

	public void contextInitialized(final ServletContextEvent arg) {
		System.out.println("创建了一个application3");
		StaticData.application = arg.getServletContext();
		StaticData.WEBINF_PATH = arg.getServletContext().getRealPath("/")
				+ "WEB-INF\\";
		System.out.println(StaticData.WEBINF_PATH);
		final DatabaseXMLManager dbxmlm = new DatabaseXMLManager();
		final DatabaseXML dbxml = dbxmlm.getDatabaseXML();
		System.out.println(dbxml.getConnection() + "\n" + dbxml.getAddress()
				+ "\n" + dbxml.getUsername() + "\n" + dbxml.getPassword());
		System.out.println(dbxml.dburl());
	}
}
